/**
 * 
 */
package com.xinlu.util.tool;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ocean
 * 
 */
public class PageObject implements Serializable {

	// 默认页面显示大小
	public static int DEFAULT_PAGE_SIZE = 10;
	private int pageSize = DEFAULT_PAGE_SIZE;

	// 开始页
	private int startIndex;

	// 列表
	List items;

	// 总共记录
	private int recordCount;

	private int newNo;

	public int getNewNo() {
		return newNo;
	}

	public void setNewNo(int newNo) {
		this.newNo = newNo;
	}

	public PageObject() {
		this(new ArrayList(), 0);
	}

	public PageObject(List items, int recordCount) {
		this.items = items;
		this.recordCount = recordCount;
	}

	public PageObject(List items, int recordCount, int startIndex) {
		this.items = items;
		this.recordCount = recordCount;
		this.startIndex = startIndex;
	}

	public PageObject(List items, int recordCount, int startIndex, int pageSize) {
		this.items = items;
		this.recordCount = recordCount;
		this.startIndex = startIndex;
		this.pageSize = pageSize;
	}

	public int getCurrentPageNo() {
		return startIndex / pageSize + 1;
	}

	public int getFirstPage() {
		return 1;
	}

	public int getEndPage() {
		return getPageCount();
	}

	public int getPageCount() {
		if (recordCount % pageSize == 0) {
			return recordCount / pageSize;
		} else {
			return recordCount / pageSize + 1;
		}
	}

	public boolean hasNextPage() {
		if (getCurrentPageNo() < getPageCount()) {
			return true;
		} else {
			return false;
		}
	}

	public boolean hasPreviousPage() {
		if (getCurrentPageNo() > 1) {
			return true;
		} else {
			return false;
		}
	}

	public boolean getNextPage() {
		return hasNextPage();
	}

	public boolean getPreviousPage() {
		return hasPreviousPage();
	}

	public static int getPageIndex(int pageNo, int pageSize) {
		return (pageNo - 1) * pageSize;
	}

	public static int getPageIndex(int pageNo) {
		return (pageNo - 1) * DEFAULT_PAGE_SIZE;
	}

	public List getItems() {
		return items;
	}

	public void setItems(List items) {
		this.items = items;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getRecordCount() {
		return recordCount;
	}

	public void setRecordCount(int recordCount) {
		this.recordCount = recordCount;
	}

	public int getStartIndex() {
		return startIndex;
	}

	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}
}
